/*     */ package com.chb.weblog.hive.mrbean;
/*     */ 
/*     */ import java.io.PrintStream;
/*     */ import java.text.ParseException;
/*     */ import java.text.SimpleDateFormat;
/*     */ import java.util.Date;
/*     */ import java.util.HashSet;
/*     */ import java.util.Locale;
/*     */ import java.util.Set;
/*     */ 
/*     */ public class KPI
/*     */ {
/*     */   private String remote_addr;
/*     */   private String remote_user;
/*     */   private String time_local;
/*     */   private String request;
/*     */   private String status;
/*     */   private String body_bytes_sent;
/*     */   private String http_referer;
/*     */   private String http_user_agent;
/*  23 */   private boolean valid = true;
/*     */ 
/*     */   private static KPI parser(String line) {
/*  26 */     System.out.println(line);
/*  27 */     KPI kpi = new KPI();
/*  28 */     String[] arr = line.split(" ");
/*  29 */     if (arr.length > 11) {
/*  30 */       kpi.setRemote_addr(arr[0]);
/*  31 */       kpi.setRemote_user(arr[1]);
/*  32 */       kpi.setTime_local(arr[3].substring(1));
/*  33 */       kpi.setRequest(arr[6]);
/*  34 */       kpi.setStatus(arr[8]);
/*  35 */       kpi.setBody_bytes_sent(arr[9]);
/*  36 */       kpi.setHttp_referer(arr[10]);
/*     */ 
/*  38 */       if (arr.length > 12)
/*  39 */         kpi.setHttp_user_agent(arr[11] + " " + arr[12]);
/*     */       else {
/*  41 */         kpi.setHttp_user_agent(arr[11]);
/*     */       }
/*     */ 
/*  44 */       if (Integer.parseInt(kpi.getStatus()) >= 400)
/*  45 */         kpi.setValid(false);
/*     */     }
/*     */     else {
/*  48 */       kpi.setValid(false);
/*     */     }
/*  50 */     return kpi;
/*     */   }
/*     */ 
/*     */   public static KPI filterPVs(String line)
/*     */   {
/*  57 */     KPI kpi = parser(line);
/*  58 */     Set pages = new HashSet();
/*  59 */     pages.add("/about");
/*  60 */     pages.add("/black-ip-list/");
/*  61 */     pages.add("/cassandra-clustor/");
/*  62 */     pages.add("/finance-rhive-repurchase/");
/*  63 */     pages.add("/hadoop-family-roadmap/");
/*  64 */     pages.add("/hadoop-hive-intro/");
/*  65 */     pages.add("/hadoop-zookeeper-intro/");
/*  66 */     pages.add("/hadoop-mahout-roadmap/");
/*     */ 
/*  68 */     if (!pages.contains(kpi.getRequest())) {
/*  69 */       kpi.setValid(false);
/*     */     }
/*  71 */     return kpi;
/*     */   }
/*     */ 
/*     */   public static KPI filterIPs(String line)
/*     */   {
/*  78 */     KPI kpi = parser(line);
/*  79 */     Set pages = new HashSet();
/*  80 */     pages.add("/about");
/*  81 */     pages.add("/black-ip-list/");
/*  82 */     pages.add("/cassandra-clustor/");
/*  83 */     pages.add("/finance-rhive-repurchase/");
/*  84 */     pages.add("/hadoop-family-roadmap/");
/*  85 */     pages.add("/hadoop-hive-intro/");
/*  86 */     pages.add("/hadoop-zookeeper-intro/");
/*  87 */     pages.add("/hadoop-mahout-roadmap/");
/*     */ 
/*  89 */     if (!pages.contains(kpi.getRequest())) {
/*  90 */       kpi.setValid(false);
/*     */     }
/*     */ 
/*  93 */     return kpi;
/*     */   }
/*     */ 
/*     */   public static KPI filterBroswer(String line)
/*     */   {
/* 100 */     return parser(line);
/*     */   }
/*     */ 
/*     */   public static KPI filterTime(String line)
/*     */   {
/* 107 */     return parser(line);
/*     */   }
/*     */ 
/*     */   public static KPI filterDomain(String line)
/*     */   {
/* 114 */     return parser(line);
/*     */   }
/*     */ 
/*     */   public String toString()
/*     */   {
/* 119 */     StringBuilder sb = new StringBuilder();
/* 120 */     sb.append("valid:" + this.valid);
/* 121 */     sb.append("\nremote_addr:" + this.remote_addr);
/* 122 */     sb.append("\nremote_user:" + this.remote_user);
/* 123 */     sb.append("\ntime_local:" + this.time_local);
/* 124 */     sb.append("\nrequest:" + this.request);
/* 125 */     sb.append("\nstatus:" + this.status);
/* 126 */     sb.append("\nbody_bytes_sent:" + this.body_bytes_sent);
/* 127 */     sb.append("\nhttp_referer:" + this.http_referer);
/* 128 */     sb.append("\nhttp_user_agent:" + this.http_user_agent);
/* 129 */     return sb.toString();
/*     */   }
/*     */ 
/*     */   public String getRemote_addr() {
/* 133 */     return this.remote_addr;
/*     */   }
/*     */ 
/*     */   public void setRemote_addr(String remote_addr) {
/* 137 */     this.remote_addr = remote_addr;
/*     */   }
/*     */ 
/*     */   public String getRemote_user() {
/* 141 */     return this.remote_user;
/*     */   }
/*     */ 
/*     */   public void setRemote_user(String remote_user) {
/* 145 */     this.remote_user = remote_user;
/*     */   }
/*     */ 
/*     */   public String getTime_local() {
/* 149 */     return this.time_local;
/*     */   }
/*     */ 
/*     */   public Date getTime_local_Date() throws ParseException {
/* 153 */     SimpleDateFormat df = new SimpleDateFormat("dd/MMM/yyyy:HH:mm:ss", Locale.US);
/* 154 */     return df.parse(this.time_local);
/*     */   }
/*     */ 
/*     */   public String getTime_local_Date_hour() throws ParseException {
/* 158 */     SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHH");
/* 159 */     return df.format(getTime_local_Date());
/*     */   }
/*     */ 
/*     */   public void setTime_local(String time_local) {
/* 163 */     this.time_local = time_local;
/*     */   }
/*     */ 
/*     */   public String getRequest() {
/* 167 */     return this.request;
/*     */   }
/*     */ 
/*     */   public void setRequest(String request) {
/* 171 */     this.request = request;
/*     */   }
/*     */ 
/*     */   public String getStatus() {
/* 175 */     return this.status;
/*     */   }
/*     */ 
/*     */   public void setStatus(String status) {
/* 179 */     this.status = status;
/*     */   }
/*     */ 
/*     */   public String getBody_bytes_sent() {
/* 183 */     return this.body_bytes_sent;
/*     */   }
/*     */ 
/*     */   public void setBody_bytes_sent(String body_bytes_sent) {
/* 187 */     this.body_bytes_sent = body_bytes_sent;
/*     */   }
/*     */ 
/*     */   public String getHttp_referer() {
/* 191 */     return this.http_referer;
/*     */   }
/*     */ 
/*     */   public String getHttp_referer_domain() {
/* 195 */     if (this.http_referer.length() < 8) {
/* 196 */       return this.http_referer;
/*     */     }
/*     */ 
/* 199 */     String str = this.http_referer.replace("\"", "").replace("http://", "").replace("https://", "");
/* 200 */     return str.indexOf("/") > 0 ? str.substring(0, str.indexOf("/")) : str;
/*     */   }
/*     */ 
/*     */   public void setHttp_referer(String http_referer) {
/* 204 */     this.http_referer = http_referer;
/*     */   }
/*     */ 
/*     */   public String getHttp_user_agent() {
/* 208 */     return this.http_user_agent;
/*     */   }
/*     */ 
/*     */   public void setHttp_user_agent(String http_user_agent) {
/* 212 */     this.http_user_agent = http_user_agent;
/*     */   }
/*     */ 
/*     */   public boolean isValid() {
/* 216 */     return this.valid;
/*     */   }
/*     */ 
/*     */   public void setValid(boolean valid) {
/* 220 */     this.valid = valid;
/*     */   }
/*     */ 
/*     */   public static void main(String[] args) {
/* 224 */     String line = "222.68.172.190 - - [18/Sep/2013:06:49:57 +0000] \"GET /images/my.jpg HTTP/1.1\" 200 19939 \"http://www.angularjs.cn/A00n\" \"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36\"";
/* 225 */     System.out.println(line);
/* 226 */     KPI kpi = new KPI();
/* 227 */     String[] arr = line.split(" ");
/*     */ 
/* 229 */     kpi.setRemote_addr(arr[0]);
/* 230 */     kpi.setRemote_user(arr[1]);
/* 231 */     kpi.setTime_local(arr[3].substring(1));
/* 232 */     kpi.setRequest(arr[6]);
/* 233 */     kpi.setStatus(arr[8]);
/* 234 */     kpi.setBody_bytes_sent(arr[9]);
/* 235 */     kpi.setHttp_referer(arr[10]);
/* 236 */     kpi.setHttp_user_agent(arr[11] + " " + arr[12]);
/* 237 */     System.out.println(kpi);
/*     */     try
/*     */     {
/* 240 */       SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd:HH:mm:ss", Locale.US);
/* 241 */       System.out.println(df.format(kpi.getTime_local_Date()));
/* 242 */       System.out.println(kpi.getTime_local_Date_hour());
/* 243 */       System.out.println(kpi.getHttp_referer_domain());
/*     */     } catch (ParseException e) {
/* 245 */       e.printStackTrace();
/*     */     }
/*     */   }
/*     */ }

/* Location:           H:\我的资料\Hadoop学习\hive\Hive视频教程\资料\day4\项目代码\step-3-运行预处理\weblog.jar
 * Qualified Name:     cn.itcast.bigdata.hive.mrbean.KPI
 * JD-Core Version:    0.6.2
 */